<?php


namespace app\api\controller;


use app\common\controller\Api;
use app\common\library\WXBizMsgCrypt;

class Work extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    //服务商回调通知
    public function serviceNotify(){
        $receiveid = "ww377c91a81493c595";
        $token = "quNyGXy6lgSyga6osNRRb0EHiUu";
        $encodingAesKey = "iyn93zifyDXYSkpLp7Rk8vPPV3xgynHg59cUXcYmDKo";
        $input = input();
        log_print($input);
        $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $receiveid);

        $sVerifyMsgSig = $_GET['msg_signature'];
        $sVerifyTimeStamp = $_GET['timestamp'];
        $sVerifyNonce = $_GET['nonce'];
        $sVerifyEchoStr = $_GET['echostr'];

        $sEchoStr = "";
        $errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
        log_print($errCode);
        if ($errCode == 0) {
            log_print($sEchoStr);
            // 验证URL成功
            return $sEchoStr;
        } else {
            log_print('回调失败');
            log_print("ERR: " . $errCode);
            return '回调失败';
        }
    }

}
